function foo(url) {
    var state
    var val
    function process(v) {
        switch (state) {
            case 1:
                console.log('requesting:', url)
                return request(url)
            case 2:
                val = v
                console.log(val)
                return
            case 3:
                var err = val
                console.log('Oops:', err)
                return false
        }
    }
    return {
        next: function (v) {
            if (!state) {
                state = 1
                return {
                    done: false,
                    value: process()
                }
            } else if (state === 1) {
                state = 2
                return {
                    done: true,
                    value: process(v)
                }
            } else {
                return {
                    done: true,
                    value: undefined
                }
            }
        },
        throw: function () {
            if (state === 1) {
                state = 3
                return {
                    done: true,
                    value: process(e)
                }
            } else {
                throw e
            }
        }
    }
}
var it = foo('http://some.url.1');
it.next()